using System;
using System.Collections;
using System.Collections.Generic;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Pegasus.UnitTests.Runtime.Serialization.Formatters.Xml.XmlFormatter2Tests
{
	/// <summary>
	/// This is a test class for Pegasus.Runtime.Serialization.Formatters.Xml.XmlFormatter2
	/// and will check the support for collections.
	///</summary>
	[TestClass]
	public class XmlFormatter2CollectionsTests
	{
		// Local Instance Values
		private TestContext m_testContextInstance;

		/// <summary>
		/// Initializes a new instance of the <see cref="T:XmlFormatter2CollectionsTests"/> class.
		/// </summary>
		public XmlFormatter2CollectionsTests()
		{
		}

		/// <summary>
		/// Gets or sets the test context which provides information about and 
		/// functionality for the current test run.
		/// </summary>
		/// <value>The test context.</value>
		public TestContext TestContext
		{
			get
			{
				return m_testContextInstance;
			}
			set
			{
				m_testContextInstance = value;
			}
		}

		/// <summary>
		/// Test the Serialize of Hashtable type.
		/// </summary>
		/// <remarks>
		/// The hashtable implements the IDeserializationCallback interface 
		/// to exercise the callback code.
		/// </remarks>
		[TestMethod]
		public void SerializeHashtable()
		{
			Hashtable table = new Hashtable();
			for( int x = 0; x < XmlFormatter2Helper.TestLoops; x++ )
			{
				table.Add( x, XmlFormatter2Helper.StringTestValue );
			}

			Hashtable newTable = (Hashtable) XmlFormatter2Helper.SerializeDeserialize( table );

			// Check test results
			int count = newTable.Count;
			Assert.IsTrue( count == XmlFormatter2Helper.TestLoops, "Table count is not right" );

			for( int x = 0; x < XmlFormatter2Helper.TestLoops; x++ )
			{
				Assert.AreEqual( (string) newTable[ x ], XmlFormatter2Helper.StringTestValue, "Table value is not right" );
			}
		}

		/// <summary>
		/// Test the Serialize of generic List&lt;string&gt; type.
		/// </summary>
		[TestMethod]
		public void SerializeGenericList()
		{
			List<string> list = new List<string>();
			for( int x = 0; x < XmlFormatter2Helper.TestLoops; x++ )
			{
				list.Add( XmlFormatter2Helper.StringTestValue );
			}

			List<string> newList = (List<string>) XmlFormatter2Helper.SerializeDeserialize( list );

			// Check test results
			int count = newList.Count;
			Assert.IsTrue( count == XmlFormatter2Helper.TestLoops, "List count is not right" );

			for( int x = 0; x < XmlFormatter2Helper.TestLoops; x++ )
			{
				Assert.AreEqual( newList[ x ], XmlFormatter2Helper.StringTestValue, "List value is not right" );
			}
		}

		/// <summary>
		/// Test the Serialize of generic Dictionary&lt;int,string&gt; type.
		/// </summary>
		[TestMethod]
		public void SerializeGenericDictionary()
		{
			Dictionary<int, string> table = new Dictionary<int, string>();
			for( int x = 0; x < XmlFormatter2Helper.TestLoops; x++ )
			{
				table.Add( x, XmlFormatter2Helper.StringTestValue );
			}

			Dictionary<int, string> newTable = (Dictionary<int, string>) XmlFormatter2Helper.SerializeDeserialize( table );

			// Check test results
			int count = newTable.Count;
			Assert.IsTrue( count == XmlFormatter2Helper.TestLoops, "List count is not right" );

			for( int x = 0; x < XmlFormatter2Helper.TestLoops; x++ )
			{
				Assert.AreEqual( newTable[ x ], XmlFormatter2Helper.StringTestValue, "List value is not right" );
			}
		}

		/// <summary>
		/// Test the Serialize of generic SortedDictionary&lt;int,string&gt; type.
		/// </summary>
		[TestMethod]
		public void SerializeSortedDictionary()
		{
/*
 * lexnn: Not working there is a bug in the TypeName object for nested generic classes.
 * 
 * 
			System._Replacement.Collections.Generic.SortedDictionary<int, string> table = new System._Replacement.Collections.Generic.SortedDictionary<int, string>();
			for( int x = 0; x < XmlFormatter2Helper.TestLoops; x++ )
			{
				table.Add( x, XmlFormatter2Helper.StringTestValue );
			}

			SortedDictionary<int, string> newTable = (SortedDictionary<int, string>) XmlFormatter2Helper.SerializeDeserialize( table );

			// Check test results
			int count = newTable.Count;
			Assert.IsTrue( count == XmlFormatter2Helper.TestLoops, "List count is not right" );

			for( int x = 0; x < XmlFormatter2Helper.TestLoops; x++ )
			{
				Assert.AreEqual( newTable[ x ], XmlFormatter2Helper.StringTestValue, "List value is not right" );
			}
*/
		}
	}
}
